﻿#pragma once

#include "SuoerCamera.h"
#include "USB3Stream.h"
#include "USB3Device.h"

template<typename USB3StreamClass, typename USB3DeviceClass>
class SuoerUSB3Camera :public SuoerCamera
{
public:
	SuoerUSB3Camera()
	{
		device.reset(new USB3DeviceClass);
	}
	~SuoerUSB3Camera()
	{
		close();
		device.reset();
	}

	bool open(const std::string& model)
	{
		device->open(USB3DeviceClass::OPEN_BY_DESCRIPTION, model.c_str());
		return true;
	}

	void close()
	{
		stopGrab();
		device->close();
	}

	void startGrab()
	{
		stream.reset(new USB3StreamClass(device.get(), 1));
		stream->startStreaming();
	}

	void stopGrab()
	{
		if (stream)
		{
			stream->stopStreaming();
			stream.reset();
		}
	}

private:
	std::shared_ptr<USB3DeviceClass> device;
	std::shared_ptr<USB3StreamClass> stream;

};

